package cn.hycat.leetcode.easy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : lzhycat
 * @date : 2022-09-01 10:24
 */
public class L1两数之和 {
        public int[] twoSum(int[] nums, int target) {
            int[] ans = new int[2];
            Map<Integer, Integer> map = new HashMap<>();
            for(int i = 0; i < nums.length; i++) {
                map.put(nums[i], i);
            }
            for(int i = 0; i < nums.length; i++) {
                if(map.get(target - nums[i]) != null &&
                !map.get(target - nums[i]).equals(i)) {
                    ans[0] = i;
                    ans[1] = map.get(target - nums[i]);
                    return ans;
                }
            }
            return null;
        }
}
